package com.itg.vms.servlet;

import com.itg.vms.entity.SystemMenu;
import com.itg.vms.service.SysMenuService;
import com.itg.vms.service.impl.SysMenuServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @create 2023年03月07日 12:45:38
 */
@WebServlet("/api/menu")
public class MenuListServlet extends BaseServlet {

    private SysMenuService sysMenuService = new SysMenuServiceImpl();

    /**
     * 得到菜单列表
     */
    public void getMenuList(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        List<SystemMenu> menuList = sysMenuService.getMenuList();
        if (menuList != null) {

            resp.getWriter().write(success(0, "获取成功", (long) menuList.size(), menuList));
        } else {
            resp.getWriter().write(error("获取失败"));
        }
    }

    /**
     * 更新菜单状态
     */
    public void updateMenuStatus(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String menuId = req.getParameter("menuId");
        int id = Integer.parseInt(menuId);
        String status = req.getParameter("status");
        int menuStatus = Integer.parseInt(status);
        //调用业务层方法
        int i = sysMenuService.updateMenuStatus(id, menuStatus);
        resp.getWriter().write(toAjax(i));
    }
}
